﻿namespace Deppton.Mobile
{
    using System;
    using Deppton.Mobile.Views;

    public class BootstrapController : IDisposable
    {
        private bool isDisposed;

        public BootstrapController()
            : this(new StaticServicesPortfolio())
        {
        }

        public BootstrapController(IServicesPortfolio portfolio)
        {
            this.Portfolio = portfolio;
            this.MainForm = new MainForm(this.Portfolio, () => new CredentialsController(portfolio));
        }

        ~BootstrapController()
        {
            this.Dispose(false);
        }

        public IServicesPortfolio Portfolio
        {
            get;
            set;
        }

        public MainForm MainForm
        {
            get;
            private set;
        }

        public void Dispose()
        {
            this.Dispose(true);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!this.isDisposed)
            {
                if (disposing)
                {
                    if (this.MainForm != null)
                    {
                        this.MainForm.Dispose();
                    }
                }

                this.isDisposed = true;
            }
        }
    }
}
